package com.cctc.framework.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.util.List;

import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import com.cctc.framework.domain.Tree;

@Repository
public class TreeDao extends BaseDao<Object>
{
    public List<Tree> getTreeObject(int parentId){
        return  (List<Tree>)getJdbcTemplate().query("SELECT id, ICON_CLS, STATE, TEXT FROM CCTC.CCTCT_TREES WHERE PARENT_ID=? ",new Object[]{parentId},new int[]{Types.INTEGER},new TreeObjectMapper());
    }
    public List<Tree> getTreeObject(String treeName){
        return  getJdbcTemplate().query("SELECT id, ICON_CLS, STATE, TEXT FROM CCTC.CCTCT_TREES WHERE TREE_NAME=?",new Object[]{treeName},new int[]{Types.VARCHAR},new TreeObjectMapper());
    }
   
    protected class TreeObjectMapper implements RowMapper<Tree>
    {
        public Tree mapRow(ResultSet rs, int rowNum) throws SQLException
        {
            Tree tree = new Tree();
            tree.setId(rs.getInt("ID"));
            tree.setIconCls(rs.getString("ICON_CLS"));
            tree.setState(rs.getString("STATE"));
            tree.setText(rs.getString("TEXT"));
            return tree;
        }
    }
}
